﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class FightEvent : DeventCenter
{
    //玩家攻击消息
    public static string RESPLAYERFIGHTRESULT = "resplayerfightResult";
    //怪物攻击消息
    public static string RESMONSTERATTACKPLAYER = "resmonsterattackplayer";

    //玩家HP改变
    public static string PlayerChangeHp = "playerchangehp";

    //=============================================================
    Dictionary<string, DelCallBack> myDicEventType;

    public FightEvent()
    {
        myDicEventType = new Dictionary<string, DelCallBack>();
    }

    public override void AddListener(string eventType, DelCallBack handler)
    {
        if (!myDicEventType.ContainsKey(eventType))
        {
            myDicEventType.Add(eventType, null);
        }
        myDicEventType[eventType] += handler;
    }

    public override void RemoveListener(string eventType, DelCallBack handler)
    {
        if (myDicEventType.ContainsKey(eventType))
        {
            myDicEventType[eventType] -= handler;
        }
    }

    public override void DispatchEvent(string eventType, object data)
    {
        if (myDicEventType.TryGetValue(eventType, out DelCallBack del))
        {
            del?.Invoke(data);
        }
    }

    public override void RemoveAllListener()
    {
        myDicEventType.Clear();
    }

    
}
